/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.giant.entities.pos;

import com.giant.authentication.User;
import com.giant.entities.Person;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Harold
 */
@Entity
@Table(name = "p_invoice")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PInvoice.findAll", query = "SELECT p FROM PInvoice p"),
    @NamedQuery(name = "PInvoice.findByIdInvoice", query = "SELECT p FROM PInvoice p WHERE p.idInvoice = :idInvoice"),
    @NamedQuery(name = "PInvoice.findByInvoiceNumber", query = "SELECT p FROM PInvoice p WHERE p.invoiceNumber = :invoiceNumber"),
    @NamedQuery(name = "PInvoice.findByDateInvoice", query = "SELECT p FROM PInvoice p WHERE p.dateInvoice = :dateInvoice"),
    @NamedQuery(name = "PInvoice.findByGrossValue", query = "SELECT p FROM PInvoice p WHERE p.grossValue = :grossValue"),
    @NamedQuery(name = "PInvoice.findByTaxValue", query = "SELECT p FROM PInvoice p WHERE p.taxValue = :taxValue"),
    @NamedQuery(name = "PInvoice.findByTotalValue", query = "SELECT p FROM PInvoice p WHERE p.totalValue = :totalValue"),
    @NamedQuery(name = "PInvoice.findByObservations", query = "SELECT p FROM PInvoice p WHERE p.observations = :observations"),
    @NamedQuery(name = "PInvoice.findByAnnuled", query = "SELECT p FROM PInvoice p WHERE p.annuled = :annuled"),
    @NamedQuery(name = "PInvoice.findByReasonAnnu", query = "SELECT p FROM PInvoice p WHERE p.reasonAnnu = :reasonAnnu"),
    @NamedQuery(name = "PInvoice.findByDateAnnu", query = "SELECT p FROM PInvoice p WHERE p.dateAnnu = :dateAnnu")})
public class PInvoice implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_invoice")
    private Integer idInvoice;
    @Basic(optional = false)
    @NotNull
    @Column(name = "invoice_number")
    private int invoiceNumber;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_invoice")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateInvoice;
    @Basic(optional = false)
    @NotNull
    @Column(name = "gross_value")
    private float grossValue;
    @Basic(optional = false)
    @NotNull
    @Column(name = "tax_value")
    private float taxValue;
    @Basic(optional = false)
    @NotNull
    @Column(name = "total_value")
    private float totalValue;
    @Size(max = 1000)
    @Column(name = "observations")
    private String observations;
    @Basic(optional = false)
    @NotNull
    @Column(name = "annuled")
    private boolean annuled;
    @Size(max = 250)
    @Column(name = "reason_annu")
    private String reasonAnnu;
    @Column(name = "date_annu")
    @Temporal(TemporalType.DATE)
    private Date dateAnnu;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idInvoice")
    private Collection<PInvoicePayment> pInvoicePaymentCollection;
    @JoinColumn(name = "id_pos", referencedColumnName = "id_pos")
    @ManyToOne(optional = false)
    private PPos idPos;
    @JoinColumn(name = "id_person", referencedColumnName = "id_person")
    @ManyToOne(optional = false)
    private Person idPerson;
    @JoinColumn(name = "id_cashbox", referencedColumnName = "id_cashbox")
    @ManyToOne(optional = false)
    private PCashbox idCashbox;
    @JoinColumn(name = "id_cashier", referencedColumnName = "id_user")
    @ManyToOne(optional = false)
    private User idCashier;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idInvoice")
    private Collection<PInvoiceSeller> pInvoiceSellerCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idInvoice")
    private Collection<PInvoiceTax> pInvoiceTaxCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idInvoice")
    private Collection<PInvoiceProd> pInvoiceProdCollection;
    @JoinColumn(name = "id_user_annu", referencedColumnName = "id_user")
    @ManyToOne(optional = false)
    private User idUserAnnu;

    public PInvoice() {
    }

    public PInvoice(Integer idInvoice) {
        this.idInvoice = idInvoice;
    }

    public PInvoice(Integer idInvoice, int invoiceNumber, Date dateInvoice, float grossValue, float taxValue, float totalValue, boolean annuled) {
        this.idInvoice = idInvoice;
        this.invoiceNumber = invoiceNumber;
        this.dateInvoice = dateInvoice;
        this.grossValue = grossValue;
        this.taxValue = taxValue;
        this.totalValue = totalValue;
        this.annuled = annuled;
    }

    public Integer getIdInvoice() {
        return idInvoice;
    }

    public void setIdInvoice(Integer idInvoice) {
        this.idInvoice = idInvoice;
    }

    public int getInvoiceNumber() {
        return invoiceNumber;
    }

    public void setInvoiceNumber(int invoiceNumber) {
        this.invoiceNumber = invoiceNumber;
    }

    public Date getDateInvoice() {
        return dateInvoice;
    }

    public void setDateInvoice(Date dateInvoice) {
        this.dateInvoice = dateInvoice;
    }

    public float getGrossValue() {
        return grossValue;
    }

    public void setGrossValue(float grossValue) {
        this.grossValue = grossValue;
    }

    public float getTaxValue() {
        return taxValue;
    }

    public void setTaxValue(float taxValue) {
        this.taxValue = taxValue;
    }

    public float getTotalValue() {
        return totalValue;
    }

    public void setTotalValue(float totalValue) {
        this.totalValue = totalValue;
    }

    public String getObservations() {
        return observations;
    }

    public void setObservations(String observations) {
        this.observations = observations;
    }

    public boolean getAnnuled() {
        return annuled;
    }

    public void setAnnuled(boolean annuled) {
        this.annuled = annuled;
    }

    public String getReasonAnnu() {
        return reasonAnnu;
    }

    public void setReasonAnnu(String reasonAnnu) {
        this.reasonAnnu = reasonAnnu;
    }

    public Date getDateAnnu() {
        return dateAnnu;
    }

    public void setDateAnnu(Date dateAnnu) {
        this.dateAnnu = dateAnnu;
    }

    public User getIdCashier() {
        return idCashier;
    }

    public void setIdCashier(User idCashier) {
        this.idCashier = idCashier;
    }

    @XmlTransient
    public Collection<PInvoicePayment> getPInvoicePaymentCollection() {
        return pInvoicePaymentCollection;
    }

    public void setPInvoicePaymentCollection(Collection<PInvoicePayment> pInvoicePaymentCollection) {
        this.pInvoicePaymentCollection = pInvoicePaymentCollection;
    }

    public PPos getIdPos() {
        return idPos;
    }

    public void setIdPos(PPos idPos) {
        this.idPos = idPos;
    }

    public Person getIdPerson() {
        return idPerson;
    }

    public void setIdPerson(Person idPerson) {
        this.idPerson = idPerson;
    }

    public PCashbox getIdCashbox() {
        return idCashbox;
    }

    public void setIdCashbox(PCashbox idCashbox) {
        this.idCashbox = idCashbox;
    }

    @XmlTransient
    public Collection<PInvoiceSeller> getPInvoiceSellerCollection() {
        return pInvoiceSellerCollection;
    }

    public void setPInvoiceSellerCollection(Collection<PInvoiceSeller> pInvoiceSellerCollection) {
        this.pInvoiceSellerCollection = pInvoiceSellerCollection;
    }

    @XmlTransient
    public Collection<PInvoiceTax> getPInvoiceTaxCollection() {
        return pInvoiceTaxCollection;
    }

    public void setPInvoiceTaxCollection(Collection<PInvoiceTax> pInvoiceTaxCollection) {
        this.pInvoiceTaxCollection = pInvoiceTaxCollection;
    }

    @XmlTransient
    public Collection<PInvoiceProd> getPInvoiceProdCollection() {
        return pInvoiceProdCollection;
    }

    public void setPInvoiceProdCollection(Collection<PInvoiceProd> pInvoiceProdCollection) {
        this.pInvoiceProdCollection = pInvoiceProdCollection;
    }

    public User getIdUserAnnu() {
        return idUserAnnu;
    }

    public void setIdUserAnnu(User idUserAnnu) {
        this.idUserAnnu = idUserAnnu;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idInvoice != null ? idInvoice.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PInvoice)) {
            return false;
        }
        PInvoice other = (PInvoice) object;
        if ((this.idInvoice == null && other.idInvoice != null) || (this.idInvoice != null && !this.idInvoice.equals(other.idInvoice))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.giant.entities.PInvoice[ idInvoice=" + idInvoice + " ]";
    }
   public String getIsCancel() {
        if(annuled == true)
        {
            return "Canceled";
        }
       return "Activated";
        
    }
}
